import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.orc.DataMaskDescription;
import org.apache.orc.OrcFile;
import org.apache.orc.RecordReader;
import org.apache.orc.TypeDescription;
import org.apache.orc.impl.ReaderImpl;

import java.io.IOException;
import java.util.List;

public class ORCFileReader {

    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();

        // 创建ORC文件的Reader对象
        ReaderImpl reader = (ReaderImpl) OrcFile.createReader(new Path("/Users/mac/606be53_1761_58890FAB.orc"), OrcFile.readerOptions(conf));

        // 获取ORC文件中的Schema
        TypeDescription schema = reader.getSchema();

        List<String> attributeNames = schema.getAttributeNames();
        System.err.println("attributeNames = " + attributeNames);


        long contentLength = reader.getContentLength();
        System.out.println("contentLength = " + contentLength);


        DataMaskDescription[] dataMasks = reader.getDataMasks();
        System.err.println("dataMasks = " + dataMasks.length);


        // 创建RecordReader对象
        RecordReader recordReader = reader.rows();




        // 遍历ORC文件中的数据
        Object row = null;



        VectorizedRowBatch batch = schema.createRowBatch();

        List<TypeDescription> children = schema.getChildren();
        System.err.println("children zw = " + children);




        List<String> fieldNames = schema.getFieldNames();
        System.out.println("fieldNames zw = " + fieldNames);


        while (recordReader.nextBatch(batch)) {
            int i=0;
            row = batch.toString();
            // 在此处处理每一行数据的逻辑
            System.out.println(row);
            ColumnVector col = batch.cols[i];

            int dataColumnCount = batch.getDataColumnCount();
            System.err.println("dataColumnCount = " + dataColumnCount);

            System.err.println("col = " + col);
            i++;

        }

        // 关闭RecordReader对象
        recordReader.close();
    }
}